package xkp.lesson6;

import java.util.ArrayList;
import java.util.LinkedList;

public class Consumer extends  Thread{
    private LinkedList<Commonity> list;

    public Consumer(LinkedList<Commonity> list) {
        this.list = list;
    }

    @Override
    public void run() {
        Thread.currentThread().setName("Consumer");
        while(true){
            synchronized (list){
                if(list.size()<100){
                    list.notifyAll();
                    try {
                        list.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else{
                    list.pop();
                    System.out.println(Thread.currentThread().getName()+":"+list.size());

                }
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
